package gitee.derumin.lifeissohard;

import gitee.derumin.lifeissohard.criteria.LishCriteria;
import gitee.derumin.lifeissohard.effects.LishStatusEffects;
import gitee.derumin.lifeissohard.item.LishItems;
import gitee.derumin.lifeissohard.tools.LishIdentifiers;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;

public class Lifeissohard implements ModInitializer {
    public static final ItemGroup LISH_ITEMS = FabricItemGroup.builder(LishIdentifiers.Items.ItemGroups.LISH_ITEMS)
            .icon(() -> new ItemStack(LishItems.BLOOD_TESTER))
            .build();

    @Override
    public void onInitialize() {
        Registry.register(Registries.ITEM , LishIdentifiers.Items.BLOOD_TESTER , LishItems.BLOOD_TESTER);
        Registry.register(Registries.ITEM , LishIdentifiers.Items.BLOOD_TESTER_USED , LishItems.BLOOD_TESTER_USED);
        Registry.register(Registries.ITEM , LishIdentifiers.Items.SMALL_SCREEN , LishItems.SMALL_SCREEN);
        Registry.register(Registries.ITEM , LishIdentifiers.Items.LARGE_SCREEN , LishItems.LARGE_SCREEN);
        Registry.register(Registries.ITEM , LishIdentifiers.Items.IMAGED_CAKE , LishItems.IMAGED_CAKE);
        Registry.register(Registries.ITEM , LishIdentifiers.Items.COOKED_EGG , LishItems.COOKED_EGG);
        Registry.register(Registries.ITEM , LishIdentifiers.Items.PROCESSING_UNIT,LishItems.PROCESSING_UNIT);
        ItemGroupEvents.modifyEntriesEvent(LISH_ITEMS).register(content -> {
            content.add(LishItems.BLOOD_TESTER);
            content.add(LishItems.BLOOD_TESTER_USED);
            content.add(LishItems.SMALL_SCREEN);
            content.add(LishItems.LARGE_SCREEN);
            content.add(LishItems.IMAGED_CAKE);
            content.add(LishItems.COOKED_EGG);
            content.add(LishItems.PROCESSING_UNIT);
        });
        Registry.register(Registries.STATUS_EFFECT , LishIdentifiers.StatusEffects.BLEEDING , LishStatusEffects.BLEEDING);
        Registry.register(Registries.STATUS_EFFECT , LishIdentifiers.StatusEffects.DIARRHEA , LishStatusEffects.DIARRHEA);
        Criteria.register(LishCriteria.NUTRITION_EFFECTS);
        ServerPlayerEvents.COPY_FROM.register((oldPlayer, newPlayer, alive) -> {
            ((PlayerEntityTools)newPlayer).setHungerManager(oldPlayer.getHungerManager());
            if (!alive) {
                ((LishHungerManager)(newPlayer.getHungerManager())).reSet();
            }
        });
        ServerPlayNetworking.registerGlobalReceiver(LishIdentifiers.Packets.C2SPackets.PLAYER_INPUT_PACKET,(((server, player, handler, buf, responseSender) -> LishNetworkPackets.applyPlayerMoveInputPacket(server,player,buf))));
    }
}
